package cn.cvs.controller;

import cn.cvs.pojo.StorageRecord;
import cn.cvs.service.StorageService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping(value = "/storageRecord")
public class StorageController {
    private Logger logger = Logger.getLogger(StorageController.class);
    @Autowired
    @Qualifier("storageServiceImpl")
    private StorageService storageService;

    @RequestMapping(value = "/list")
    public String list(Model model, @RequestParam(defaultValue = "1") Integer pageIndex,String goodsName,String supName,Integer payStatus){
        Integer pageSize = 6 ;
        int totalCount = storageService.count(goodsName);
        int totalPageCount = totalCount/pageSize;
        if (totalCount%pageSize>0){
            totalPageCount++;
        }
        if (pageIndex>totalPageCount){
            pageIndex=totalPageCount;
        }

        List<StorageRecord> storageRecordList= storageService.list(goodsName,supName,payStatus,pageIndex,pageSize);
        model.addAttribute("storageRecordList",storageRecordList);
        model.addAttribute("goodsName",goodsName);
        model.addAttribute("supName",supName);
        model.addAttribute("payStatus",payStatus);
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("totalPageCount",totalPageCount);
        model.addAttribute("currentPageNo",pageIndex);
        return "storageRecord/list";

    }

}
